package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OutBean;
import com.project.service.OutService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.LocalDate;

@Controller
@RequestMapping("out")
public class OutController {

    @Resource
    private OutService outService;

    //分页显示所有出库信息
    @RequestMapping("findAllOut")
    @ResponseBody
    public IPage<OutBean> findAllOut(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                     @RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
        return outService.findAllOut(pageNo,pageSize);
    }

    //添加出库信息
    @RequestMapping("addMeOut")
    @ResponseBody
    public String addMeOut(int outId,int[] array,int num){
        outService.addMeOut(outId,array,num);
        return "ok";
    }

    //添加物品
    @RequestMapping("addOut")
    @ResponseBody
    public String addOut(OutBean outBean){
        outService.addOut(outBean);
        return "ok";
    }


    //根据出库明细id修改领用数量
    @RequestMapping("updateOutNum")
    @ResponseBody
    public String updateOutNum(int Id,int num){
        outService.updateOutNum(Id,num);
        return "ok";
    }

    //根据出库信息去删除物品信息
    @RequestMapping("del")
    @ResponseBody
    public String del(int outId, int meId){
        outService.del(outId,meId);
        return "ok";
    }


    //根据出库id查询出库信息
    @RequestMapping("findId")
    @ResponseBody
    public OutBean findId(int outId){
        return outService.findId(outId);
    }


    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<OutBean> findName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                   @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                   String outClass, LocalDate startTime, LocalDate endTime){
       return outService.findName(pageNo,pageSize,outClass,startTime,endTime);
    }
}
